package the.guanzhong.express.interfaces.controller;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.wisteria.framework.web.APIResult;
import the.broccoli.setting.service.IParamsService;
import the.guanzhong.express.interfaces.controller.req.CargoListReq;
import the.guanzhong.express.interfaces.controller.resp.CargoListResp;
import the.guanzhong.express.interfaces.controller.resp.ShopBetweenResp;
import the.guanzhong.express.service.ExpressCargoService;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 获取信息控制器
 */
@Api(tags = "Express")
@Slf4j
@RestController
@RequestMapping("/express/cargo")
public class ExpressCargoController {

    @Resource
    private ExpressCargoService expressCargoService;

    @Resource
    private IParamsService paramsService;

    /**
     * 获取货物列表
     * @return
     */
    @PostMapping("/list")
    public APIResult<List<CargoListResp>> getCargoList() {
        List<CargoListResp> dataList = null;
        String content = paramsService.getValue("EXPRESS_CARGO");
        if (StringUtils.hasText(content)) {
            dataList = JSON.parseArray(content, CargoListResp.class);
        }
        return APIResult.success(dataList);
    }

    /**
     * 查询货物类别
     * @param req   查询条件
     * @return
     */
    @PostMapping("/list/v2")
    public APIResult<Map<String, ShopBetweenResp>> getCargoList(@RequestBody @Valid CargoListReq req) {
        return APIResult.success(expressCargoService.getCargoList(req));
    }

    /**
     * 货物信息
     * @return
     */
    @GetMapping("/str")
    public APIResult<String> getCargoStr() {
        return APIResult.success(expressCargoService.getCargoStr());
    }
}
